/**
 * 排除body key
 * @param {key} string 
 */
export function excludeBodyKey(key="") {
    const exludeKeys = ['er_bxcontrast', 'er_cshare_detail', 'accrued_verify']
    if(exludeKeys.indexOf(key) < 0) {
        return true
    }
    return false
}

export function getDefaultTableButtons(key) {
    return [
        {
            area: `${key}_card_body`,
            btncolor: "button_secondary",
            children: [],
            isenable: true,
            key: `${key}_Add`,
            keyboard: "Alt+N",
            order: "29",
            pageareacode: `${key}`,
            title: "201103INUP-0008", //"增行",
            type: "general_btn"
        },
        {
            area: `${key}_card_body`,
            btncolor: "button_secondary",
            children: [],
            isenable: true,
            key: `${key}_wallet`,
            keyboard: "Alt+N",
            order: "29",
            pageareacode: `${key}`,
            title: "201103INUP-0006", // "票夹",
            type: "general_btn"
        },
        {
            area: `${key}_card_body`,
            btncolor: "button_secondary",
            children: [],
            isenable: true,
            key: `${key}_upload`,
            keyboard: "Alt+N",
            order: "29",
            pageareacode: `${key}`,
            title: "201103INUP-0007", // "发票上传",
            type: "general_btn"
        },
        {
            area: `${key}_card_body_inner`,
            btncolor: "button_secondary",
            children: [],
            isenable: true,
            key: `${key}_Edit`,
            keyboard: "F4",
            order: "33",
            pageareacode: key,
            title: "201103INUP-0009", // "展开",
            type: "general_btn",
        },
        {
            area: `${key}_card_body_inner`,
            btncolor: "button_secondary",
            children: [],
            isenable: true,
            key: `${key}_Delete`,
            keyboard: "Alt+Del",
            order: "34",
            pageareacode: key,
            title: "201103INUP-0001", // "删除",
            type: "general_btn",
        },
        {
            area: `${key}_card_body_inner`,
            btncolor: "button_secondary",
            children: [],
            id: "1001A4100000000140DR",
            isenable: true,
            key: `${key}_Insert`,
            keyboard: "Alt+I",
            order: "43",
            pageareacode: key,
            title: "201103INUP-0010", // "插入",
            type: "general_btn",
        },
        {
            area: `${key}_card_body_inner`,
            btncolor: "button_secondary",
            children: [],
            isenable: true,
            key: `${key}_Copy`,
            keyboard: "Alt+C",
            order: "44",
            pageareacode: key,
            title: "201103INUP-0011", // "复制",
            type: "general_btn",
        }
    ]
}
/**
 * 
 * @param {*} rate_category 当前汇率类型
 * @param {*} windowTypes 所有汇率类型
 * @returns Y：五种类型之一，N：非五种类型，-1：空
 */
export function getZzhllxValue(rate_category = '',windowTypes){
    if(rate_category.display){
        let curType = windowTypes.find((item) => {
            return item.display === rate_category.display
        })
        let value = curType.value
        if(value == '0' || value == '1' || value == '2' || value == '3' || value == '4') return 'Y'
        return 'N'
    } else {
        return -1
    }
}

/**
 * 汇率适配逻辑
 * currentrow_bzbm:当前币种，
 * rate_category：汇率类型，
 * type: 'head',表单，'body‘，表体，
 * props:props
 * moduleId:当前页签
 * rowid:当前行
 */
 export function zzhllxLogic(currentrow_bzbm,rate_category,type,props,moduleId,rowid){
    let zzbwb = window.presetVar.zzbwb //组织币种
    let ratecontorl = window.presetVar.ratecontorl   // 集团参数NC004 N 不允许修改，Y 允许修改
    let zzhllxValue = getZzhllxValue(rate_category,window.presetVar.zzhllxs)  // Y:五种中的一种，N:非五种，-1：空
    let editKeys = []
    let unEditKeys = []
    if(currentrow_bzbm && currentrow_bzbm.value == zzbwb){
        unEditKeys = ['bbhl','zzhllx']
        editKeys = ['zzhllyrq']
        if(zzhllxValue < 0){
            unEditKeys = ['zzhllyrq','bbhl','zzhllx']
            editKeys = []
            type == 'head' ? props.form.setFormItemsValue(presetVar.head.head1,{'zzhllyrq':{display: null, value: null}}) : props.cardTable.setValByKeyAndRowId(moduleId, rowid, 'zzhllyrq',{value:null, display: null}) //清空组织汇率来源日期
        }
    } else if( zzhllxValue =='Y' && ratecontorl == 'N'){  //缺少对应5种组织汇率类型及集团参数判断
        unEditKeys = ['bbhl']
        editKeys = ['zzhllyrq','zzhllx']
    }  else if(zzhllxValue < 0){
        unEditKeys = ['zzhllyrq']
        editKeys = ['bbhl','zzhllx']
        type == 'head' ? props.form.setFormItemsValue(presetVar.head.head1,{'zzhllyrq':{display: null, value: null}}) : props.cardTable.setValByKeyAndRowId(moduleId, rowid, 'zzhllyrq',{value:null, display: null}) //清空组织汇率来源日期
    } else{
        unEditKeys = []
        editKeys = ['bbhl','zzhllyrq','zzhllx']
    }
    if(type == 'head'){
        editKeys.forEach((item) => {
            props.form.setFormItemsDisabled('head',{[item]: false});
        })
        unEditKeys.forEach((item) => {
            props.form.setFormItemsDisabled('head',{[item]: true});
        })
    } else{
        props.cardTable.setEditableByRowId(moduleId, rowid, editKeys, true)
        props.cardTable.setEditableByRowId(moduleId, rowid, unEditKeys, false)
    }
     
}

/**
 * 判断某行是否真的未删除(组件有问题，行已删除getClickRowIndex竟然还能获取到，并且行不是删除状态，使用该方法进一步判断)
 * props:props
 * moduleId:当前页签
 * row:当前行
 */
 export function rowExists(props, moduleId, rowId){
    let rows = props.cardTable.getVisibleRows(moduleId);
    if(rows && rows.length > 0) {
        for (const r of rows) {
            if(r.rowid ==  rowId) {
                return true;
            }
        }
    }
    return false;
 }